package com.itheima.appserver.service;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.appserver.config.MyThreadLocal;
import com.itheima.commons.pojo.UserInfo;
import com.itheima.commons.vo.UserInfoVo;
import com.itheima.dubbo.interfaces.UserInfoApi;
import org.springframework.stereotype.Service;

/**
 * @项目名称: tanhua-53
 * @包名: com.itheima.appserver.service
 * @作者: 李云飞
 * @日期: 2021-12-09
 */

@Service
public class MyCenterService {

    @Reference
    private UserInfoApi userInfoApi;

    // 根据用户的ID查询用户的信息
    public UserInfoVo queryUserInfoByUserId(Long userId) {
        UserInfo userInfo = userInfoApi.findById(ObjectUtil.isEmpty(userId) ? MyThreadLocal.getUserId() : userId);

        UserInfoVo userInfoVo = new UserInfoVo();
        // 用户的ID
        userInfoVo.setId(userInfo.getUserId());
        userInfoVo.setAvatar(userInfo.getLogo());
        userInfoVo.setNickname(userInfo.getNickName());
        userInfoVo.setBirthday(userInfo.getBirthday());
        userInfoVo.setAge(userInfo.getAge().toString());
        userInfoVo.setGender(userInfo.getSex() == 1 ? "man" : "woman");
        userInfoVo.setCity(userInfo.getCity());
        userInfoVo.setEducation(userInfo.getEdu());
        userInfoVo.setIncome(userInfo.getIncome());
        userInfoVo.setProfession(userInfo.getIndustry());
        userInfoVo.setMarriage(userInfo.getMarriage() == "已婚" ? 1 : 0);

        return userInfoVo;
    }
}
